package com.example.administrator.himalaya.criticallies;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.himalaya.R;
import com.example.administrator.himalaya.adapter.SubscibeAdapter;
import com.example.administrator.himalaya.fragment.FragmentHistory;
import com.example.administrator.himalaya.fragment.FragmentSubscibe;
import com.example.administrator.himalaya.fragment.FragmentrRecommend;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class SecondFragment extends Fragment {


    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<Fragment> fragments;
    private List<String> title;

    public SecondFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_second, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout = (TabLayout) view.findViewById(R.id.tab_layput_fragement_second);
        viewPager = (ViewPager) view.findViewById(R.id.view_pager_fragment_second);
        fragments = new ArrayList<>();
        fragments.add(new FragmentrRecommend());
        fragments.add(new FragmentSubscibe());
        fragments.add(new FragmentHistory());
        title = new ArrayList<>();
        title.add("推荐");
        title.add("订阅");
        title.add("历史");
        SubscibeAdapter subscibeAdapter =new SubscibeAdapter(getChildFragmentManager(),title,fragments,getContext());
        viewPager.setAdapter(subscibeAdapter);
        tabLayout.setupWithViewPager(viewPager);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

    }

    public ViewPager getViewPager() {
        return viewPager;
    }

    public void setViewPager(ViewPager viewPager) {
        this.viewPager = viewPager;
    }
}
